package com.altius.twitapp;

import java.util.Calendar;

import javax.el.ELContext;
import javax.el.ELResolver;
import javax.faces.context.FacesContext;

public class TwitAdderBean {
    private String text;

    public void add() {
        ELContext el = FacesContext.getCurrentInstance().getELContext();
        ELResolver resolver = FacesContext.getCurrentInstance()
                .getApplication().getELResolver();

        TwitViewerBean viewer = (TwitViewerBean) resolver.getValue(el, null,
                "twitViewer");
        viewer.getTwits().add(new Twit(text, Calendar.getInstance().getTime()));
        viewer.sort(viewer.getTwits());
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
}
